<?php
declare (strict_types=1);

namespace app\console;

use zhanshop\App;
use zhanshop\console\Command;
use zhanshop\console\Input;
use zhanshop\console\Output;
use zhanshop\client\Httpclient;

class Test extends Command
{

    public function configure()
    {
       $this->useCache()->useDatabase();
    }

    public function execute(Input $input, Output $output)
    {
        $data = file_get_contents('/Users/zhangqiquan/Documents/phpdev/zhanshop-marketing/test/测试广告数据/luyin-adupload.json');
        $data = json_decode($data, true);
        foreach ($data as $v){
            $platform = $v['platform'];
            if($platform == 'baidu'){
                $this->$platform($v);
            }
        }
    }

    public function byte($data)
    {

    }

    public function baidu($data)
    {
        $params = json_decode($data['params'], true);
        $aid = $params['aid'];
        $pid = $params['pid'];
        $uid = $params['uid'];
        $userid = $params['userid'] ? $params['userid'] : '__USER_ID__';
        $clickid = $params['click_id'] ? $params['click_id'] : '__CLICK_ID__';
        $idfa = $params['idfa'] ? $params['idfa'] : '__IDFA__';
        $imei = $data['imei'] ? $data['imei'] : '__IMEI__';
        $androidId = $data['android_id'] ? $data['android_id'] : '__ANDROIDID__';
        $ip = $data['ipv4'] ? $data['ipv4'] : $data['ipv6'];
        $ua = urlencode($data['ua'] ? $data['ua'] : '__UA__');
        $ts = $params['ts'] ? $params['ts'] : '__TS__';
        $extInfo = $params['ext_info'] ? $params['ext_info'] : '__EXT_INFO__';
        $oaid = $data['oaid'] ? $data['oaid'] : '__OAID__';
        $oaidmd5 = $params['oaid_md5'] ? $params['oaid_md5'] : '__OAID_MD5__';
        $size = $params['size'] ? $params['size'] : '__SIZE__';
        $bdvid = $params['bd_vid'] ? $params['bd_vid'] : '__SIZE__';
        $url = 'http://jia-test-marketing.zhanshop.cn:8000/v1/ad.listen/manfen/baidu/click/06JWulc6Rrbm29K0FX_2BO_2BqZp1PoNR_2FgbMoZSgGA3Gh4Dw9RmvwcOmhe6q5Gblsx_2B?aid='.$aid.'&pid='.$pid.'&uid='.$uid.'&userid='.$userid.'&click_id='.$clickid.'&idfa='.$idfa.'&imei='.$imei.'&android_id='.$androidId.'&ip='.$ip.'&ua='.$ua.'&os=__OS__&ts='.$ts.'&ext_info='.$extInfo.'&mac_md5=__MAC1__&mac=__MAC__&oaid='.$oaid.'&oaid_md5='.$oaidmd5.'&comb_id=__COMBID__&size='.$size.'&deeplink_url=__DEEPLINK_URL__&bd_vid='.$bdvid.'&callType=v2&akey='.($params['akey'] ?? 'null').'&ip_type='.($params['ip_type'] ?? 'null').'&sign='.($params['sign'] ?? 'null');
        $ok = (new Httpclient())->enableIpv6()->request($url);
        var_dump($ok['code']);
    }

    public function vivo($data)
    {

    }

    public function kuaishou($data)
    {

    }
}


// 小米 百度 荣耀 好了